package com.tabjin.rfidsocket.common.utils;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author tabjin
 * create at 2020/10/27 17:46
 * @program food
 * @description 自定义响应数据结构
 * 本类可提供给 H5/ios/安卓/公众号/小程序 使用
 * 前端接受此类数据（json object)后，可自行根据业务去实现相关功能
 * <p>
 * 200：表示成功
 * 500：表示错误，错误信息在msg字段中
 * 501：bean验证错误，不管多少个错误都以map形式返回
 * 502：拦截器拦截到用户token出错
 * 555：异常抛出信息
 * 556: 用户qq校验异常
 */
public class TabJsonResultCM {
    // 定义jackson对象
    private static final ObjectMapper MAPPER = new ObjectMapper();

    // 响应业务状态
    private Integer code;

    // 响应消息
    private String message;

    @JsonIgnore
    private String ok;    // 不使用

    public static TabJsonResultCM build(Integer code, String message) {
        return new TabJsonResultCM(code, message);
    }

    public static TabJsonResultCM build(Integer code, String message, String ok) {
        return new TabJsonResultCM(code, message, ok);
    }

    public static TabJsonResultCM ok() {
        return new TabJsonResultCM();
    }

    public static TabJsonResultCM errorMsg(String message) {
        return new TabJsonResultCM(500, message);
    }

    public static TabJsonResultCM errorTokenMessage(String message) {
        return new TabJsonResultCM(502, message);
    }

    public static TabJsonResultCM errorException(String message) {
        return new TabJsonResultCM(555, message, null);
    }

    public static TabJsonResultCM errorUserQQ(String message) {
        return new TabJsonResultCM(556, message, null);
    }

    public TabJsonResultCM(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public TabJsonResultCM(Integer code, String message, String ok) {
        this.code = code;
        this.message = message;
        this.ok = ok;
    }

    public TabJsonResultCM() {
        this.code = 200;
        this.message = "success";
    }

    public Boolean isOK() {
        return this.code == 200;
    }

    public Integer getCOde() {
        return code;
    }

    public void setStatus(Integer status) {
        this.code = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getOk() {
        return ok;
    }

    public void setOk(String ok) {
        this.ok = ok;
    }
}
